import request from '@/utils/request'
import type { CategoryResponseData, AttrResponseData, Attr } from './type'
enum API {
  GETCATEGORY1_URL = '/admin/product/getCategory1',
  GETCATEGORY2_URL = '/admin/product/getCategory2/',
  GETCATEGORY3_URL = '/admin/product/getCategory3/',
  GETATTRlIST_URL = '/admin/product/attrInfoList/',
  GETATTRINFO_URL = '/admin/product/saveAttrInfo',
  DELETEATTR_URL = '/admin/product/deleteAttr/'
}

// 获取一级分类
export const getCategory1Service = () =>
  request.get<any, CategoryResponseData>(API.GETCATEGORY1_URL)

// 获取二级分类
export const getCategory2Service = (category1Id: number) =>
  request.get<any, CategoryResponseData>(API.GETCATEGORY2_URL + category1Id)

// 获取三级分类
export const getCategory3Service = (category2Id: number) =>
  request.get<any, CategoryResponseData>(API.GETCATEGORY3_URL + category2Id)

// 获取商品基础属性
export const getAttrListService = (
  category1Id: number | string,
  category2Id: number | string,
  category3Id: number | string
) =>
  request.get<any, AttrResponseData>(
    API.GETATTRlIST_URL + category1Id + '/' + category2Id + '/' + category3Id
  )

// 获取商品属性信息
export const addAttrInfoService = (data: Attr) =>
  request.post<any, any>(API.GETATTRINFO_URL, data)

// 删除属性信息
export const deleteAttrService = (attrId: number) =>
  request.delete<any, any>(API.DELETEATTR_URL + attrId)
